<template>
  <div style="width:100%;overflow:hidden">
    <weui-panel :list="panel_list" style="overflow-y:auto;height:100%" @on-click="on_panel_click">
    </weui-panel>
  </div>
</template>

<script>
  import WeuiPanel from '../vue2componentSet/src/components/WeuiPanel'
  import global from '../lib/global'
  import browserDetect from '../lib/browserDetect'
  import axios from 'axios'

  export default {
    components: {
      WeuiPanel
    },
    data() {
      return {
        panel_list: [],
        url: '',
      }
    },
    mounted() {
      this.$store.commit('set_title', 'rss')

      !!location.hash.split('?')[1] && location.hash.split('?')[1].split('&').forEach(item => {
        this[item.split('=')[0]] = item.split('=')[1];
      })

      if (!this.url) {
        this.$router.push('/')
        return;
      }

      axios.get(global.server + 'rss.do?url=' + this.url).then(result => {
        const obj = result.data
        if (obj.result == -1) {
          //this.$router.push('/')
          return;
        }
        obj.rss.forEach(item => {
          this.panel_list.push({
            title: item.title[0],
            desc: item.description[0],
            infos: [item.author[0], item.pubDate[0]],
            link: item.link[0]
          })
        })
      })
    },
    methods: {
      on_panel_click(index) {
        if (0 && browserDetect().Safari) {
          location.href = this.panel_list[index].link
        } else {
          const node = document.getElementById('open-url')
          node.href = this.panel_list[index].link
          node.click()
        }
      }
    }
  }
</script>
